import { ApiCall } from "tsrpc";
import bag_component from "../../component/bag_component";
import gameCfg from "../../gameCfg";
import player from "../../core/rpg/entity/player";
import sdk from '../../core/index';
import { ComType } from "../../core/tool/component";
import { ReqList, ResList, ResbagItem } from "../../shared/api_client/bag/PtlList";


export default async function (call: ApiCall<ReqList, ResList>) {
    let user = call.req._player as player;
    let com_bag = user.getComponent(ComType.背包) as bag_component;
    let resList: ResbagItem[] = [];

    com_bag.getItemList().forEach((val, idx) => {
        resList.push({
            id: val.id,
            type: val.type,
            name: val.name,
            emoji: val.emoji,
            icon: val.icon || gameCfg.defaultIcon,
            cont: val.count,
            quality: val.quality
        })
    })
    call.succ({ list: resList })
}
